﻿using System.Windows;
using PSE.Deployment.SetupBase;
using PSE.Deployment.SetupBase.UI;
using Sinacor.Deployment.Setup.Main;
using System.Windows.Input;

namespace Sinacor.Deployment.Setup.UI
{
    /// <summary>
    /// Interaction logic for TermoLicenca.xaml
    /// </summary>
    public partial class License : BaseWizardWindow
    {
        public License()
        {
            this.InitializeComponent();
            LoadConfiguration();
        }

        private void LoadConfiguration()
        {
            rdlAccept.IsChecked = SetupMainFactory.GetInstance<SinacorMain>().Parameter.Licence.Accepted;
            rdlDecline.IsChecked = !SetupMainFactory.GetInstance<SinacorMain>().Parameter.Licence.Accepted;
        }

        private void AcceptedValues()
        {
            SetupMainFactory.GetInstance<SinacorMain>().Parameter.Licence.Accepted = rdlAccept.IsChecked.GetValueOrDefault();
        }

        protected override void OnNextClick(RoutedEventArgs e)
        {
            base.OnNextClick(e);
            AcceptedValues();
        }

        protected override void OnPreviousClick(RoutedEventArgs e)
        {
            base.OnPreviousClick(e);
            AcceptedValues();
        }

        private void rdlAccept_Checked(object sender, RoutedEventArgs e)
        {
            this.AllowNext = true;
        }

        private void rdlDecline_Checked(object sender, RoutedEventArgs e)
        {
            this.AllowNext = false;
        }

        private void lnkBmfBovespa_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri));

            e.Handled = true;
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == System.Windows.Input.Key.Left)
            {
                rdlAccept.IsChecked = true;
            }
            else if (e.Key == System.Windows.Input.Key.Right)
            {
                rdlDecline.IsChecked = true;
            }
        }
    }
}
